package org.mock.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import org.mock.common.R;
import org.mock.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

import org.mock.entity.TestExam;
import org.mock.dto.TestExamDTO;
import org.mock.service.TestExamService;

/**
 * @author AI
 * @since 2025-08-20
 */
@RestController
@AllArgsConstructor
@RequestMapping("testExam")
public class TestExamController {

    private TestExamService testExamService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<TestExam> detail(TestExamDTO dto) {
        TestExam detail = testExamService.getOne(dto);
        return R.data(detail);
    }

    /**
     * 分页
     */
    @GetMapping("/page")
    public R<IPage<TestExam>> page(TestExamDTO dto) {
        IPage<TestExam> pages = testExamService.page(dto);
        return R.data(pages);
    }

    /**
     * 不分页
     */
    @GetMapping("/list")
    public R<List<TestExam>> list(TestExamDTO dto) {
        List<TestExam> list = testExamService.list(dto);
        return R.data(list);
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    public R save(@RequestBody TestExamDTO dto) {
        return R.data(testExamService.save(dto));
    }

    /**
     * 批量新增
     */
    @PostMapping("/saveBatch")
    public R save(@RequestBody JSONObject request) {
        return R.data(testExamService.saveBatch(request));
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody TestExamDTO dto) {
        return R.data(testExamService.updateById(dto));
    }

    /**
     * 删除
     */
    @DeleteMapping("/remove")
    public R remove(@RequestParam String ids) {
        return R.data(testExamService.deleteLogic(Func.toIntList(ids)));
    }

}
